package com.besall.allbase.view.activity.chipstoollevel4.protocol;

import static com.besall.allbase.bluetooth.service.Protocol.ProtocolConstants.*;

import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.bes.bessdk.BesSdkConstants;
import com.bes.bessdk.service.base.BBServiceListener;
import com.bes.bessdk.service.base.BesServiceConfig;
import com.bes.bessdk.service.base.BesServiceListener;
import com.bes.bessdk.utils.ArrayUtil;
import com.bes.bessdk.utils.SPHelper;
import com.bes.sdk.utils.SettingsJsonUtils;
import com.besall.allbase.bluetooth.BluetoothConstants;
import com.besall.allbase.bluetooth.scan.ScanActivity;
import com.besall.allbase.bluetooth.service.Protocol.ProtocolConstants;
import com.besall.allbase.bluetooth.service.Protocol.ProtocolService;
import com.besall.allbase.common.utils.ActivityUtils;
import com.besall.allbase.common.utils.FileUtils;
import com.besall.allbase.view.activity.chipstoollevel4.protocol.DevelopParams.LogListActivity;
import com.besall.allbase.view.base.BasePresenter;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class ProtocolPresenter extends BasePresenter<IProtocolActivity> implements IProtocolPresenter {
	private static ProtocolPresenter instance = null;
	public final String TAG = getClass().getSimpleName();
	Context mContext;
	private ProtocolService protocolService;

	// add by wangsm
	public static synchronized ProtocolPresenter getInstance() {
		if (instance == null) {
			instance = new ProtocolPresenter();
		}
		return instance;
	}

	public ProtocolService getProtocolService() {
		return protocolService;
	}

	public void setProtocolServiceListener(BesServiceListener listener) {
		if (listener != null && protocolService != null) {
			protocolService.setBesServiceListener(listener);
		}
	}

	public void setProtocolBBServiceListener(BBServiceListener listener) {
		if (listener != null && protocolService != null) {
			protocolService.setBBServiceListener(listener);
		}
	}

	// end by wangsm
	@Override public void pickDecice(ProtocolActivity context, int scan) {
		Intent intent = new Intent();
		intent.putExtra(BluetoothConstants.Scan.BES_SCAN, scan);
		ActivityUtils.gotoActForResult(intent, BluetoothConstants.Scan.REQUEST_CODE_SCAN, context, ScanActivity.class);
	}

	@Override public void connectDevice(BesServiceConfig serviceConfig, BesServiceListener listener, Context context) {
		mContext = context;
		protocolService = new ProtocolService(serviceConfig, listener, context);
	}

	@Override public void sendInfoData(int id, byte[] params) {
		Log.i(TAG, "getInfoData: " + id);
		BesSdkConstants.BES_BLE_GIVEUP_TRANS_VALUE = false;
		if (protocolService != null) {
			if (id == ProtocolConstants.INFO_Get_personal_information) {
				protocolService.getInfoData();
			} else if (id == INFO_Get_Device_Time) {
				protocolService.getDeviceTime();
			} else if (id == INFO_Get_Battery_level) {
				protocolService.INFO_Get_Battery_level();
			} else if (id == INFO_Get_device_worn_status) {
				protocolService.INFO_Get_device_worn_status();
			} else if (id == INFO_Get_device_charge_status) {
				protocolService.INFO_Get_device_charge_status();
			} else if (id == INFO_Get_lift_wrist_to_view_setting_old) {
				protocolService.INFO_Get_lift_wrist_to_view_setting_old();
			} else if (id == INFO_Get_lift_wrist_to_view_setting_new) {
				protocolService.INFO_Get_lift_wrist_to_view_setting_new();
			} else if (id == INFO_Get_serial_number) {
				protocolService.INFO_Get_serial_number();
			} else if (id == INFO_Get_temp_params) {
				protocolService.INFO_Get_temp_params();
			} else if (id == INFO_Get_distance_unit) {
				protocolService.INFO_Get_distance_unit();
			} else if (id == INFO_Get_mac_address) {
				protocolService.INFO_Get_mac_address();
			} else if (id == INFO_Get_firmware_version) {
				protocolService.INFO_Get_firmware_version();
			} else if (id == INFO_Get_the_automatic_heart_rate_interval) {
				protocolService.INFO_Get_the_automatic_heart_rate_interval();
			} else if (id == INFO_Get_sound_volume) {
				protocolService.INFO_Get_sound_volume();
			} else if (id == INFO_Get_Phone_book) {
				protocolService.INFO_Get_Phone_book();
			} else if (id == INFO_Get_watch_size) {
				protocolService.INFO_Get_watch_size();
			} else if (id == INFO_get_Amazon_mic_test_volume) {
				protocolService.INFO_get_Amazon_mic_test_volume();
			} else if (id == INFO_config_weather_control_info) {
				protocolService.INFO_config_weather_control_info();
			} else if (id == INFO_switch_and_get_broadcast_name_and_mac_address_of_BT) {
				protocolService.INFO_switch_and_get_broadcast_name_and_mac_address_of_BT();
			} else if (id == INFO_Unbind_BT) {
				protocolService.INFO_Unbind_BT();
			} else if (id == INFO_Set_personal_information) {
				protocolService.INFO_Set_personal_information(params);
			} else if (id == INFO_Set_Time__Format) {
				protocolService.INFO_Set_Time__Format(params);
			} else if (id == INFO_Set_Device_mode) {
				protocolService.INFO_Set_Device_mode(params);
			} else if (id == INFO_Set_Pairing_phone_type) {
				protocolService.INFO_Set_Pairing_phone_type(params);
			} else if (id == INFO_Set_Device_Time) {
				protocolService.INFO_Set_Device_Time();
			} else if (id == INFO_Set_Time_Zone_time) {
				protocolService.INFO_Set_Time_Zone_time();
			} else if (id == INFO_Set_band_screens) {
				protocolService.INFO_Set_band_screens();
			} else if (id == INFO_Set_Hand_preference) {
				protocolService.INFO_Set_Hand_preference(params);
			} else if (id == INFO_Set_lift_wrist_to_view_setting_old) {
				protocolService.INFO_Set_lift_wrist_to_view_setting_old(params);
			} else if (id == INFO_Set_lift_wrist_to_view_setting_new) {
				protocolService.INFO_Set_lift_wrist_to_view_setting_new(params);
			} else if (id == INFO_Set_serial_number) {
				protocolService.INFO_Set_serial_number(params);
			} else if (id == INFO_Set_connection_key) {
				protocolService.INFO_Set_connection_key(params);
			} else if (id == INFO_Set_the_time_interval_of_the_probe_function) {
				protocolService.INFO_Set_the_time_interval_of_the_probe_function(params);
			} else if (id == INFO_Set_temperature_display_type) {
				protocolService.INFO_Set_temperature_display_type(params);
			} else if (id == INFO_Set_Device_auto_monitor_Temp) {
				protocolService.INFO_Set_Device_auto_monitor_Temp(params);
			} else if (id == INFO_Set_distance_display_unit) {
				protocolService.INFO_Set_distance_display_unit(params);
			} else if (id == INFO_set_sound_volume) {
				protocolService.INFO_set_sound_volume(params);
			} else if (id == INFO_set_Phone_book) {
				protocolService.INFO_set_Phone_book(params);
			} else if (id == INFO_set_Amazon_Alexa_state) {
				protocolService.INFO_set_Amazon_Alexa_state(params);
			} else if (id == INFO_set_Amazon_Alexa_Status) {
				protocolService.INFO_set_Amazon_Alexa_Status(params);
			} else if (id == INFO_Set_screen_brightness) {
				protocolService.INFO_Set_screen_brightness(params);
			} else if (id == INFO_set_Amazon_mic_test) {
				protocolService.INFO_set_Amazon_mic_test(params);
			}
		}
	}

	@Override public void sendFitnessData(int id, byte[] params) {
		BesSdkConstants.BES_BLE_GIVEUP_TRANS_VALUE = false;
		if (protocolService != null) {
			if (id == FIT_GET_FITNESS_DAILY_VALUE) {
				protocolService.FIT_GET_FITNESS_DAILY_VALUE(params);
			} else if (id == FIT_GET_ECG_HISTROY_DATA) {
				protocolService.FIT_GET_ECG_HISTROY_DATA(params);
			} else if (id == FIT_GET_AUTO_ECG_DATA) {
				protocolService.FIT_GET_AUTO_ECG_DATA(params);
			} else if (id == FIT_GET_HISTROY_TEMP) {
				protocolService.FIT_GET_HISTROY_TEMP(params);
			} else if (id == FIT_GET_5_MINUTES_WALK) {
				protocolService.FIT_GET_5_MINUTES_WALK(params);
			} else if (id == FIT_GET_HOURLY_WALK_DATA) {
				protocolService.FIT_GET_HOURLY_WALK_DATA(params);
			} else if (id == FIT_GET_10_MINUTES_SLEEP) {
				protocolService.FIT_GET_10_MINUTES_SLEEP(params);
			} else if (id == FIT_GET_SPO2_RAW_125hz) {
				protocolService.FIT_GET_SPO2_RAW_125hz(params);
			} else if (id == FIT_GET_LATEST_HEALTH_DATA) {
				protocolService.FIT_GET_LATEST_HEALTH_DATA(params);
			} else if (id == FIT_GET_1_MINUTES_SLEEP) {
				protocolService.FIT_GET_1_MINUTES_SLEEP(params);
			} else if (id == FIT_GET_5_MINUTES_RUNNING) {
				protocolService.FIT_GET_5_MINUTES_RUNNING(params);
			} else if (id == FIT_GET_CLIMBING_HISTROY) {
				protocolService.FIT_GET_CLIMBING_HISTROY(params);
			} else if (id == FIT_GET_1_MINUTES_CYCLING) {
				protocolService.FIT_GET_1_MINUTES_CYCLING(params);
			} else if (id == FIT_GET_ACTIVITE_HISTROY) {
				protocolService.FIT_GET_ACTIVITE_HISTROY(params);
			} else if (id == FIT_GET_HISTROY_RR_INTERVAL) {
				protocolService.FIT_GET_HISTROY_RR_INTERVAL(params);
			} else if (id == FIT_GET_GPS_DATA) {
				protocolService.FIT_GET_GPS_DATA(params);
			} else if (id == FIT_OBTAIN_HR_BP_VALUE) {
				protocolService.FIT_OBTAIN_HR_BP_VALUE(null);
			} else if (id == FIT_GET_PROXIMLY_ALART) {
				protocolService.FIT_GET_PROXIMLY_ALART(null);
			} else if (id == FIT_GET_LIVE_TEMP_DATA) {
				protocolService.FIT_GET_LIVE_TEMP_DATA(params);
			} else if (id == FIT_GET_CONTACT_TRACING_SUMMARY) {
				protocolService.FIT_GET_CONTACT_TRACING_SUMMARY(null);
			} else if (id == FIT_GET_CONTACT_TRACING_SPECIFIED) {
				// protocolService.FIT_GET_CONTACT_TRACING_SPECIFIED(params);
			} else if (id == FIT_GET_HISTROY_PPG_RAW) {
				protocolService.FIT_GET_HISTROY_PPG_RAW(params);
			} else if (id == FIT_GET_HISTROY_ACC_RAW) {
				protocolService.FIT_GET_HISTROY_ACC_RAW(params);
			} else if (id == FIT_GET_SEDENTARY_ALART) {
				protocolService.FIT_GET_SEDENTARY_ALART(params);
			} else if (id == FIT_GET_ACTIVITY_CONFIG) {
				protocolService.FIT_GET_ACTIVITY_CONFIG(null);
			} else if (id == FIT_GET_ACTIVITY_CONFIG_NEW) {
				protocolService.FIT_GET_ACTIVITY_CONFIG_NEW(null);
			} else if (id == FIT_GET_ACTIVITY_CONFIG_SUMMARY) {
				protocolService.FIT_GET_ACTIVITY_CONFIG_SUMMARY(params);
			} else if (id == FIT_GET_ACTIVITY_CONFIG_DETAIL) {
				// protocolService.FIT_GET_ACTIVITY_CONFIG_DETAIL(params);
			} else if (id == FIT_GET_SP02_PARA) {
				protocolService.FIT_GET_SP02_PARA();
			} else if (id == FIT_GET_SP02_DATA) {
				protocolService.FIT_GET_SP02_DATA(params);
			} else if (id == FIT_GET_SLEEP_TARGET_VALUE) {
				protocolService.FIT_GET_SLEEP_TARGET_VALUE();
			} else if (id == FIT_GET_SLEEP_SUMMARY_DATA) {
				protocolService.FIT_GET_SLEEP_SUMMARY_DATA(params);
			} else if (id == FIT_GET_SENSAI_CONFIG) {
				protocolService.FIT_GET_SENSAI_CONFIG(null);
			} else if (id == FIT_GET_SENSAI_SUMMARY) {
				protocolService.FIT_GET_SENSAI_SUMMARY(params);
			} else if (id == FIT_GET_SENSAI_DETAIL) {
				protocolService.FIT_GET_SENSAI_DETAIL(params);
			} else if (id == FIT_GET_HISTROY_DISTANCE) {
				protocolService.FIT_GET_HISTROY_DISTANCE(params);
			} else if (id == FIT_GET_HISTROY_CALORIE) {
				protocolService.FIT_GET_HISTROY_CALORIE(params);
			} else if (id == FIT_GET_TODAY_FITNESS) {
				protocolService.FIT_GET_TODAY_FITNESS(null);
			} else if (id == FIT_GET_HISTROY_STRESS) {
				protocolService.FIT_GET_HISTROY_STRESS(params);
			} else if (id == FIT_GET_FIRMWARE_CAPABILITY) {
				protocolService.FIT_GET_FIRMWARE_CAPABILITY(null);
			} else if (id == FIT_GET_4H_FUNCTION) {
				protocolService.FIT_GET_4H_FUNCTION(null);
			} else if (id == FIT_GET_ACTIVITY_GUIDE) {
				protocolService.FIT_GET_ACTIVITY_GUIDE(null);
			} else if (id == FIT_SET_DAILY_WALKING) {
				protocolService.FIT_SET_DAILY_WALKING(params);
			} else if (id == FIT_SET_AUTO_HR_INTERVAL) {
				protocolService.FIT_SET_AUTO_HR_INTERVAL(params);
			} else if (id == FIT_SET_ECG_RAW_DATA) {
				protocolService.FIT_SET_ECG_RAW_DATA(params);
			} else if (id == FIT_SET_HR_LIVE_CONTROL) {
				protocolService.FIT_SET_HR_LIVE_CONTROL(params);
			} else if (id == FIT_SET_SPO2_LIVE_CONTROL) {
				protocolService.FIT_SET_SPO2_LIVE_CONTROL(params);
			} else if (id == FIT_SET_ERASE_FITNESS_DATA) {
				protocolService.FIT_SET_ERASE_FITNESS_DATA(params);
			} else if (id == FIT_SET_BP_LIVE_CONTROL) {
				protocolService.FIT_SET_BP_LIVE_CONTROL(params);
			} else if (id == FIT_SET_SPORT_MODE) {
				protocolService.FIT_SET_SPORT_MODE(params);
			} else if (id == FIT_SET_UPDATA_HR_ZONE_VALUE) {
				protocolService.FIT_SET_UPDATA_HR_ZONE_VALUE(params);
			} else if (id == FIT_SET_UPDATA_VO2_MAX_VALUE) {
				protocolService.FIT_SET_UPDATA_VO2_MAX_VALUE(params);
			} else if (id == FIT_SET_LIVE_STEPS_CONTROL) {
				protocolService.FIT_SET_LIVE_STEPS_CONTROL(params);
			} else if (id == FIT_SET_GPS_CONTROL) {
				protocolService.FIT_SET_GPS_CONTROL(params);
			} else if (id == FIT_SET_SPORT_MODE_PAUSE) {
				protocolService.FIT_SET_SPORT_MODE_PAUSE(params);
			} else if (id == FIT_SET_SYNC_BP_PARAMS) {
				// protocolService.FIT_SET_SYNC_BP_PARAMS(params);
			} else if (id == FIT_SET_CLEAR_USER_BP_DATA) {
				protocolService.FIT_SET_CLEAR_USER_BP_DATA(params);
			} else if (id == FIT_SET_CLEAR_CONTACT_TRACING_DATA) {
				protocolService.FIT_SET_CLEAR_CONTACT_TRACING_DATA(params);
			} else if (id == FIT_SET_AUTO_PPG_INTERVAL) {
				protocolService.FIT_SET_AUTO_PPG_INTERVAL(params);
			} else if (id == FIT_SET_AUTO_ACC_INTERVAL) {
				protocolService.FIT_SET_AUTO_ACC_INTERVAL(params);
			} else if (id == FIT_SET_SPO2_PERIODIC) {
				protocolService.FIT_SET_SPO2_PERIODIC(params);
			} else if (id == FIT_SET_SLEEP_TARGET_VALUE) {
				protocolService.FIT_SET_SLEEP_TARGET_VALUE(params);
			} else if (id == FIT_SET_STRESS_CONFIG) {
				protocolService.FIT_SET_STRESS_CONFIG(params);
			} else if (id == FIT_SET_HAR_CONFIG) {
				protocolService.FIT_SET_HAR_CONFIG(params);
			} else if (id == FIT_GET_HAR_CONFIG) {
				protocolService.FIT_GET_HAR_CONFIG();
			} else if (id == FIT_SET_SENSAI_CONFIG) {
				protocolService.FIT_SET_SENSAI_CONFIG(params);
			} else if (id == FIT_SET_START_DESIGNATED_ACT) {
				protocolService.FIT_SET_START_DESIGNATED_ACT(params);
			}
		}
	}

	@Override public void sendNotifyData(int id, byte[] params) {
		if (protocolService != null) {
			switch (id) {
				case ALARM_GET_ALARM_INFO:
					protocolService.ALARM_GET_ALARM_INFO(params);
					break;
				case ALARM_GET_DND_setting:
					protocolService.ALARM_GET_DND_setting(params);
					break;
				case ALARM_GET_WATCH_FACE_LIST:
					protocolService.ALARM_GET_WATCH_FACE_LIST(params);
					break;
				case ALARM_GET_CUR_WATCH_FACE_ID:
					protocolService.ALARM_GET_CUR_WATCH_FACE_ID(params);
					break;
				case ALARM_GET_SPORTS_NOTIFI_STATUS:
					protocolService.ALARM_GET_SPORTS_NOTIFI_STATUS(params);
					break;
				case ALARM_GET_IMAGE_LIST:
					protocolService.ALARM_GET_IMAGE_LIST(params);
					break;
				case ALARM_GET_WATCH_BK_IMGID:
					protocolService.ALARM_GET_WATCH_BK_IMGID(params);
					break;
				case ALARM_GET_QUICK_REPLY_LIST:
					protocolService.ALARM_GET_QUICK_REPLY_LIST(params);
					break;
				case ALARM_GET_WOMEN_HEALTH_DATA:
					protocolService.ALARM_GET_WOMEN_HEALTH_DATA(params);
					break;
				case ALARM_GET_FIND_WATCH:
					protocolService.ALARM_GET_FIND_WATCH(params);
					break;
				case ALARM_GET_FIND_WATCH_START:
					protocolService.ALARM_GET_FIND_WATCH_START(params);
					break;
				case ALARM_SET_DEVICE_EVENT:
					protocolService.ALARM_SET_DEVICE_EVENT(params);
					break;
				case ALARM_SET_SEDENTARY_ALART:
					protocolService.ALARM_SET_SEDENTARY_ALART(params);
					break;
				case ALARM_SET_MUSIC_STATUS:
					protocolService.ALARM_SET_MUSIC_STATUS(params);
					break;
				case ALARM_SET_MESSAGE_ALART:
					protocolService.ALARM_SET_MESSAGE_ALART(params);
					break;
				case ALARM_SET_MESSAGE_CONTENT:
					protocolService.ALARM_SET_MESSAGE_CONTENT(params);
					break;
				case ALARM_SET_ALARM_INFO:
					protocolService.ALARM_SET_ALARM_INFO(params);
					break;
				case ALARM_SET_MEETING_SYNC:
					protocolService.ALARM_SET_MEETING_SYNC(params);
					break;
				case ALARM_SET_MEETING_DELETE:
					protocolService.ALARM_SET_MEETING_DELETE(params);
					break;
				case ALARM_SET_DND_MODE:
					protocolService.ALARM_SET_DND_MODE(params);
					break;
				case ALARM_SET_MUSIC_ARTIST:
					protocolService.ALARM_SET_MUSIC_ARTIST(params);
					break;
				case ALARM_SET_MUSIC_NAME:
					protocolService.ALARM_SET_MUSIC_NAME(params);
					break;
				case ALARM_SET_STOP_CUR_MESSAGE:
					protocolService.ALARM_SET_STOP_CUR_MESSAGE(params);
					break;
				case ALARM_SET_CUR_WATCH_FACE_ID:
					protocolService.ALARM_SET_CUR_WATCH_FACE_ID(params);
					break;
				case ALARM_SET_DELETE_WATCH_FACE_ID:
					protocolService.ALARM_SET_DELETE_WATCH_FACE_ID(params);
					break;
				case ALARM_SET_SPORTS_NOTIFY_SWITCH:
					protocolService.ALARM_SET_SPORTS_NOTIFY_SWITCH(params);
					break;
				case ALARM_SET_DELETE_IMAGE:
					protocolService.ALARM_SET_DELETE_IMAGE(params);
					break;
				case ALARM_SET_WATCH_FACE_BK_IMG:
					protocolService.ALARM_SET_WATCH_FACE_BK_IMG(params);
					break;
				case ALARM_SET_UP_QUICK_REPLY_LIST:
					protocolService.ALARM_SET_UP_QUICK_REPLY_LIST(params);
					break;
				case ALARM_SET_WOMEN_HEALTH_DATA:
					protocolService.ALARM_SET_WOMEN_HEALTH_DATA(params);
					break;
				default:
					break;
			}
		}
	}

	public void sendVibratorData(int id, byte[] params) {
		if (protocolService != null) {
			switch (id) {
				case VIBRATOR_GET_CONFIG:
					protocolService.VIBRATOR_GET_CONFIG(params);
					break;
				case VIBRATOR_SET_CONFIG:
					protocolService.VIBRATOR_SET_CONFIG(params);
					break;
				default:
					break;
			}
		}
	}

	public void sendSystemData(int id, byte[] params) {
		if (protocolService != null) {
			switch (id) {
				case SYSTEM_GET_BRIGHT_SCREEN_TIME:
					protocolService.SYSTEM_GET_BRIGHT_SCREEN_TIME(params);
					break;
				case SYSTEM_DIAGNOSTICS_MODE:
					protocolService.SYSTEM_DIAGNOSTICS_MODE(params);
					break;
				case SYSTEM_DIAGNOSTICS_MODE_CONFIG:
					protocolService.SYSTEM_DIAGNOSTICS_MODE_CONFIG(params);
					break;
				case SYSTEM_RESET_SYSTEM:
					protocolService.SYSTEM_RESET_SYSTEM(params);
					break;
				case SYSTEM_POWER_OFF:
					protocolService.SYSTEM_POWER_OFF(params);
					break;
				case SYSTEM_POWER_SAVING_CONFIG:
					protocolService.SYSTEM_POWER_SAVING_CONFIG(params);
					break;
				case SYSTEM_GET_POWER_STATUS:
					protocolService.SYSTEM_GET_POWER_STATUS(params);
					break;
				case SYSTEM_GET_SILENCE_MODE:
					protocolService.SYSTEM_GET_SILENCE_MODE(params);
					break;
				case SYSTEM_SET_SILENCE_MODE_CONFIG:
					protocolService.SYSTEM_GET_SILENCE_MODE_CONFIG(params);
					break;
				default:
					break;
			}
		}
	}

	@Override public void sendDeveloperData(int id, byte[] params) {
		Log.i(TAG, "sendDeveloperData: " + id);
		BesSdkConstants.BES_BLE_GIVEUP_TRANS_VALUE = false;
		if (protocolService != null) {
			if (id == TEST_GET_LOG_FILE_NAME) {
				protocolService.TEST_GET_LOG_FILE_NAME();
			} else if (id == TEST_REQUEST_LOG_BY_FILE_NAME) {
				protocolService.TEST_REQUEST_LOG_BY_FILE_NAME(params);
			} else if (id == TEST_START_LOG_OUTPUT) {
				protocolService.TEST_START_LOG_OUTPUT(params);
			} else if (id == TEST_WATCH_DIAL_OTA) {
				String fileName = (String) SPHelper.getPreference(mContext, KEY_WATCH_DIAL_ID, "");
				Log.i(TAG, "sendDeveloperData: " + fileName);
				protocolService.transSystemCommonFile(mContext, ArrayUtil.toASCII(params), fileName);
			} else if (id == SYSTEM_TRANS_WORKOUT_LIST_FILE) {
				String fileName = (String) SPHelper.getPreference(mContext, KEY_WORKOUT_LIST_FILE_ID, "");
				Log.i(TAG, "sendDeveloperData KEY_WORKOUT_LIST_FILE_ID: " + fileName);
				protocolService.transSystemCommonFile(mContext, ArrayUtil.toASCII(params), fileName);
			} else if (id == SYSTEM_TRANS_LUSHU_FILE) {
				String fileName = (String) SPHelper.getPreference(mContext, KEY_LUSHU_FILE_ID, "");
				Log.i(TAG, "sendDeveloperData KEY_LUSHU_FILE_ID: " + fileName);
				protocolService.transSystemCommonFile(mContext, ArrayUtil.toASCII(params), fileName);
			} else if (id == SYSTEM_TRANS_SETTING_FILE) {
				String fileName = (String) SPHelper.getPreference(mContext, KEY_SETTING_FILE_ID, "");
				Log.i(TAG, "sendDeveloperData KEY_SETTING_FILE_ID: " + fileName);
				protocolService.transSystemCommonFile(mContext, ArrayUtil.toASCII(params), fileName);
			} else if (id == SYSTEM_TRANS_WIFI_OTA_FILE) {
				String fileName = (String) SPHelper.getPreference(mContext, KEY_WIFI_OTA_FILE_ID, "");
				Log.i(TAG, "sendDeveloperData KEY_WIFI_OTA_FILE_ID: " + fileName);
				protocolService.transSystemCommonFile(mContext, ArrayUtil.toASCII(params), fileName);
			} else if (id == SYSTEM_TRANS_LOCATION_FILE) {
				String fileName = (String) SPHelper.getPreference(mContext, KEY_LOCATION_FILE_ID, "");
				Log.i(TAG, "sendDeveloperData KEY_LOCATION_FILE_ID: " + fileName);
				protocolService.transSystemCommonFile(mContext, ArrayUtil.toASCII(params), fileName);
			}
		}
	}

	public void getBikeWatchDataFromBesClient(int id, String model_name, String sn_number, String... param) {
		Log.i(TAG, "getBikeWatchDataFromBesClient: " + id);
		BesSdkConstants.BES_BLE_GIVEUP_TRANS_VALUE = false;
		if (mContext == null) {
			return;
		}
		String jsonFileDir;
		String fileName;

		if (protocolService != null) {
			if (id == ProtocolConstants.BIKEWATCH_get_personal_info) {
				protocolService.bikewatch_get_personal_info(SettingsJsonUtils.USERPROFILE_JSON);
			} else if (id == ProtocolConstants.BIKEWATCH_set_personal_info) {
				jsonFileDir = FileUtils.checkExternalDirectoryPathExist(true, model_name, sn_number, SettingsJsonUtils.SETTINGS, SettingsJsonUtils.USERPROFILE_JSON);
				fileName = SettingsJsonUtils.USERPROFILE_JSON;
				protocolService.bikewatch_set_personal_info(mContext, fileName, jsonFileDir);
			} else if (id == ProtocolConstants.BIKEWATCH_get_bicycle_info) {
				protocolService.bikewatch_get_bicycle_info(SettingsJsonUtils.GEAR_PROFILE_JSON);
			} else if (id == ProtocolConstants.BIKEWATCH_set_bicycle_info) {
				jsonFileDir = FileUtils.checkExternalDirectoryPathExist(true, model_name, sn_number, SettingsJsonUtils.SETTINGS, SettingsJsonUtils.GEAR_PROFILE_JSON);
				fileName = SettingsJsonUtils.GEAR_PROFILE_JSON;
				protocolService.bikewatch_set_bicycle_info(mContext, fileName, jsonFileDir);
			} else if (id == ProtocolConstants.BIKEWATCH_get_settings_info) {
				protocolService.bikewatch_get_settings_info(SettingsJsonUtils.SETTING_JSON);
			} else if (id == ProtocolConstants.BIKEWATCH_set_settings_info) {
				jsonFileDir = FileUtils.checkExternalDirectoryPathExist(true, model_name, sn_number, SettingsJsonUtils.SETTINGS, SettingsJsonUtils.SETTING_JSON);
				fileName = SettingsJsonUtils.SETTING_JSON;
				protocolService.bikewatch_set_settings_info(mContext, fileName, jsonFileDir);
			} else if (id == ProtocolConstants.BIKEWATCH_Reset_settings) {
				protocolService.bikewatch_reset_settings(SettingsJsonUtils.SETTING_JSON);
			} else if (id == ProtocolConstants.BIKEWATCH_Reset_device) {
				protocolService.bikewatch_reset_device(SettingsJsonUtils.SETTING_JSON);
			} else if (id == ProtocolConstants.BIKEWATCH_get_track_summary) {
				protocolService.bikewatch_get_track_summary("workout.list");
			} else if (id == ProtocolConstants.BIKEWATCH_DEL_ALL_track) {
				jsonFileDir = FileUtils.checkExternalDirectoryPathExist(true, model_name, sn_number, SettingsJsonUtils.WORKOUTS_FOLDER, "workout.list");
				fileName = jsonFileDir.substring(jsonFileDir.lastIndexOf(File.separatorChar) + 1);
				Log.i(TAG, "fileName: " + fileName);
				protocolService.bikewatch_del_all_track(fileName, jsonFileDir);
			} else if (id == ProtocolConstants.BIKEWATCH_GET_PANELS_INFO) {
				fileName = SettingsJsonUtils.PANEL_JSON;
				protocolService.getPanelsInfo(fileName);
			} else if (id == ProtocolConstants.BIKEWATCH_GET_EMMC_INFO) {
				protocolService.getEmmcInfo();
			} else if (id == ProtocolConstants.BIKEWATCH_GET_ICOE_DATA_LEFT_TIME) {
				protocolService.getIcoeDataLeftTime();
			} else if (id == ProtocolConstants.BIKEWATCH_GET_BB_OFFLINE_LOG_DATA) {
				protocolService.getBBofflineLog();
			} else if (id == ProtocolConstants.BIKEWATCH_GET_BB_OFFLINE_CONFIG_LIST) {
				protocolService.getBBofflineLogConfigList();
			} else if (id == ProtocolConstants.BIKEWATCH_GET_BB_OFFLINE_LOG_LEVEL_INFO) {
				protocolService.getBBofflineLogLevelInfo();
			} else if (id == ProtocolConstants.BIKEWATCH_SET_BB_OFFLINE_LOG_LEVEL_INFO) {
				protocolService.setBBofflineLogLevelInfo(param[0]);
			} else if (id == ProtocolConstants.BIKEWATCH_SET_BB_PKG_MTU_MAX) {
				protocolService.setBBPkgMtuMax(model_name);
			} else if (id == BIKEWATCH_GET_ROUTE_BOOKS_INFO) {
				fileName = SettingsJsonUtils.ROUTE_BOOKS_JSON;
				protocolService.getRouteBooksInfo(fileName);
			}
		} else {
			Log.d(TAG, "protocolService is null");
		}
	}

	@Override public void sendWatchDialOTA(List<byte[]> packets, long milliS) {
		if (protocolService != null) {
			protocolService.sendPacketsWithDelay(packets, milliS);
		}
	}

	@Override public void pickLogFile(ProtocolActivity context, List<String> file) {
		Intent intent = new Intent();
		intent.putStringArrayListExtra("a", (ArrayList<String>) file);
		ActivityUtils.gotoActForResult(intent, REQUEST_LOG_FILE, context, LogListActivity.class);
		// ActivityUtils.gotoAct(intent, context, LogListActivity.class);
	}

	public void sendBikeWatchDeleteFiles(Context context, List<String> listFiles, int cmdId) {
		Log.i(TAG, "sendBikeWatchDeleteFiles,listFiles size: " + listFiles.size());
		protocolService.bikewatch_del_track(listFiles, cmdId);
	}

	public void sendBikeWatchRouteBooksFiles(Context context, List<String> listFiles) {
		Log.i(TAG, "sendBikeWatchRouteBooksFiles,listFiles size: " + listFiles.size());
		protocolService.transRouteBooksFiles(listFiles);
	}

	public void getBikeWatchTracksFilesFromBesClient(Context context, List<String> listFiles) {
		Log.i(TAG, "getBikeWatchTracksFilesFromBesClient,listFiles size: " + listFiles.size());
		try {
			Thread.sleep(10);
			protocolService.getTracksFiles(listFiles);
		} catch (InterruptedException e) {
			throw new RuntimeException(e);
		}
	}

	public void saveLanXingRouteBooksFiles(Context context, List<String> listFiles) {
		Log.i(TAG, "saveLanXingRouteBooksFiles,listFiles size: " + listFiles.size());
		protocolService.saveFilesList(listFiles);
	}

	public void giveUpTransFiles(Context context) {
		Log.i(TAG, "giveUpTransFiles ");
		protocolService.bikewatch_send_giveup_trans_file(context);
	}

	public void sendIcoeKey() {
		Log.i(TAG, "sendIcoeKey");
		protocolService.bikewatch_send_icoe_public_key();
	}
}
